This program examines blocks that only partially intersect with community districts.
The starting point for downloading most Census shapefiles is here. You can find more about the census redistricting files here.
It helps to know the FIPS (Federal Information Processing System) codes for Kansas (20) and Missouri (29).
The important counties for this program are
Cass County, MO (29037) Clay County, MO (29047) Jackson County, MO (29095) Johnson County, KS (20091) Leavenworth County, KS (20103) Platte County, MO (29165) Wyandotte County, KS (20209)
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(magrittr)
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
path_name <- "../data/"
load(paste0(path_name, "bl", ".RData"))
glimpse(bl)
## Rows: 39,903
## Columns: 4
## $ bl_id <chr> "200910518012010", "200910514003006", "200910515002005", "200~
## $ bl_name <chr> "Block 2010", "Block 3006", "Block 2005", "Block 1009", "Bloc~
## $ bl_area <dbl> 38500.823, 51711.677, 104537.047, 73933.762, 95854.528, 19934~
## $ geometry <POLYGON [°]> POLYGON ((-94.64213 38.9774..., POLYGON ((-94.63966 3~
load(paste0(path_name, "cd", ".RData"))
glimpse(cd)
## Rows: 59
## Columns: 4
## $ cd_id <dbl> 106, 108, 113, 102, 129, 116, 114, 101, 105, 103, 107, 109, 1~
## $ cd_name <chr> "East Side", "Old Northeast", "Greater Downtown", "Blue Valle~
## $ cd_area <dbl> 281713850, 118237219, 181920811, 216842678, 412671242, 264282~
## $ geometry <POLYGON [°]> POLYGON ((-94.52337 39.0941..., POLYGON ((-94.50777 3~
load(paste0(path_name, "icd", ".RData"))
glimpse(icd)
## Rows: 15,748
## Columns: 19
## $ bl_id <chr> "290950023002014", "290950063002017", "290950022003001",~
## $ bl_name <chr> "Block 2014", "Block 2017", "Block 3001", "Block 3004", ~
## $ bl_area <dbl> 14983.197, 9597.627, 18151.722, 18380.541, 17691.230, 17~
## $ st_id <chr> "29", "29", "29", "29", "29", "29", "29", "29", "29", "2~
## $ co_id <chr> "29095", "29095", "29095", "29095", "29095", "29095", "2~
## $ tr_id <chr> "29095002300", "29095006300", "29095002200", "2909500220~
## $ bg_id <chr> "290950023002", "290950063002", "290950022003", "2909500~
## $ people <chr> "62", "0", "22", "26", "42", "49", "43", "0", "12", "20"~
## $ housing_units <chr> "18", "0", "9", "18", "22", "22", "14", "0", "1", "10", ~
## $ land_area <chr> "14996", "9606", "18167", "18396", "17706", "17473", "32~
## $ water_area <chr> "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "~
## $ block_lat <chr> "+39.0894021", "+39.0439974", "+39.0932160", "+39.093298~
## $ block_lon <chr> "-094.5318307", "-094.5610343", "-094.5240738", "-094.52~
## $ cd_id <dbl> 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 1~
## $ cd_name <chr> "East Side", "East Side", "East Side", "East Side", "Eas~
## $ cd_area <dbl> 281713850, 281713850, 281713850, 281713850, 281713850, 2~
## $ geometry <GEOMETRY [°]> POLYGON ((-94.5324 39.0887,..., POLYGON ((-94.5~
## $ in_area <dbl> 14983.19694, 9597.62653, 18151.72239, 18380.54058, 17691~
## $ pct_in <dbl> 100.0000000, 100.0000000, 100.0000000, 100.0000000, 100.~
icd %>%
mutate(dev=abs(pct_in-50)) %>%
arrange(dev) -> dev
dev %>%
print(n=20)
## Simple feature collection with 15748 features and 19 fields
## Geometry type: GEOMETRY
## Dimension: XY
## Bounding box: xmin: -94.90847 ymin: 38.8247 xmax: -94.38535 ymax: 39.35635
## Geodetic CRS: NAD83
## First 20 features:
## bl_id bl_name bl_area st_id co_id tr_id
## 13731 202090440023008 Block 3008 38784.788 20 20209 20209044002
## 13731.1 202090440023008 Block 3008 38784.788 20 20209 20209044002
## 21619 290470208022021 Block 2021 53718.568 29 29047 29047020802
## 32452 290950130032035 Block 2035 14588.518 29 29095 29095013003
## 32452.1 290950130032035 Block 2035 14588.518 29 29095 29095013003
## 33457 290950163003006 Block 3006 8740.562 29 29095 29095016300
## 33457.1 290950163003006 Block 3006 8740.562 29 29095 29095016300
## 10843.2 202090402001004 Block 1004 1716.527 20 20209 20209040200
## 13509 202090430002016 Block 2016 12572.542 20 20209 20209043000
## 13509.1 202090430002016 Block 2016 12572.542 20 20209 20209043000
## 37499.1 291650302013030 Block 3030 2601.423 29 29165 29165030201
## 37499 291650302013030 Block 3030 2601.423 29 29165 29165030201
## 10843.1 202090402001004 Block 1004 1716.527 20 20209 20209040200
## 13517 202099805001033 Block 1033 8292.725 20 20209 20209980500
## 13517.1 202099805001033 Block 1033 8292.725 20 20209 20209980500
## 29503 290950124003004 Block 3004 2729.426 29 29095 29095012400
## 39142 291650302013032 Block 3032 306528.920 29 29165 29165030201
## 39142.1 291650302013032 Block 3032 306528.920 29 29165 29165030201
## 11734 202090430002019 Block 2019 4040.513 20 20209 20209043000
## 11734.1 202090430002019 Block 2019 4040.513 20 20209 20209043000
## bg_id people housing_units land_area water_area block_lat
## 13731 202090440023 0 0 0 38818 +39.0776326
## 13731.1 202090440023 0 0 0 38818 +39.0776326
## 21619 290470208022 0 1 53765 0 +39.2414677
## 32452 290950130032 0 0 14600 0 +38.9332667
## 32452.1 290950130032 0 0 14600 0 +38.9332667
## 33457 290950163003 0 0 0 8748 +39.0410114
## 33457.1 290950163003 0 0 0 8748 +39.0410114
## 10843.2 202090402001 0 0 1718 0 +39.1521906
## 13509 202090430002 0 0 12583 0 +39.0502035
## 13509.1 202090430002 0 0 12583 0 +39.0502035
## 37499.1 291650302013 24 1 2604 0 +39.2628936
## 37499 291650302013 24 1 2604 0 +39.2628936
## 10843.1 202090402001 0 0 1718 0 +39.1521906
## 13517 202099805001 0 0 0 8300 +39.0984894
## 13517.1 202099805001 0 0 0 8300 +39.0984894
## 29503 290950124003 20 2 2731 0 +39.0349930
## 39142 291650302013 141 65 306801 0 +39.2640389
## 39142.1 291650302013 141 65 306801 0 +39.2640389
## 11734 202090430002 0 0 4044 0 +39.0492891
## 11734.1 202090430002 0 0 4044 0 +39.0492891
## block_lon cd_id cd_name cd_area in_area
## 13731 -094.7434580 216 Muncie Industrial 71793697 19470.0171
## 13731.1 -094.7434580 214 Morris 197287075 19314.7708
## 21619 -094.4586843 122 Shoal Creek Valley 907142727 26475.4817
## 32452 -094.5274130 132 Hickman Mills 168097252 7178.7392
## 32452.1 -094.5274130 127 Bannister West 190962384 7409.7784
## 33457 -094.5209358 102 Blue Valley 216842678 4259.7065
## 33457.1 -094.5209358 101 Blue Ridge 381892901 4480.8555
## 10843.2 -094.6519222 203 Northeast 102304904 881.2921
## 13509 -094.6394875 210 Shawnee Heights 73299753 6478.9517
## 13509.1 -094.6394875 209 Rosedale 64911356 6093.5901
## 37499.1 -094.6009456 124 KCI 1453755078 1347.3418
## 37499 -094.6009456 123 Gashland 511184945 1254.0810
## 10843.1 -094.6519222 219 Quindaro Bluffs 86913571 827.4271
## 13517 -094.6125643 208 Armourdale 113096389 4329.1369
## 13517.1 -094.6125643 202 Central Indust. Dist. 17353951 3963.5880
## 29503 -094.4371574 101 Blue Ridge 381892901 1301.9518
## 39142 -094.6251877 121 Line Creek Valley 588793273 146019.5571
## 39142.1 -094.6251877 124 KCI 1453755078 160509.3970
## 11734 -094.6468606 211 Argentine 108911247 2117.4709
## 11734.1 -094.6468606 210 Shawnee Heights 73299753 1923.0426
## pct_in dev geometry
## 13731 50.20014 0.2001381 POLYGON ((-94.74175 39.0779...
## 13731.1 49.79986 0.2001381 POLYGON ((-94.74511 39.0772...
## 21619 49.28553 0.7144685 POLYGON ((-94.45635 39.2447...
## 32452 49.20815 0.7918528 POLYGON ((-94.5281 38.93329...
## 32452.1 50.79185 0.7918529 POLYGON ((-94.52675 38.9332...
## 33457 48.73493 1.2650735 POLYGON ((-94.52097 39.0430...
## 33457.1 51.26507 1.2650735 POLYGON ((-94.52094 39.0428...
## 10843.2 51.34157 1.3415739 POLYGON ((-94.65145 39.1529...
## 13509 51.53255 1.5325521 POLYGON ((-94.63498 39.0533...
## 13509.1 48.46745 1.5325521 POLYGON ((-94.64096 39.0492...
## 37499.1 51.79250 1.7924953 POLYGON ((-94.60092 39.2632...
## 37499 48.20750 1.7924953 POLYGON ((-94.60092 39.2625...
## 10843.1 48.20355 1.7964528 POLYGON ((-94.65153 39.1529...
## 13517 52.20403 2.2040337 POLYGON ((-94.61271 39.0988...
## 13517.1 47.79597 2.2040338 POLYGON ((-94.61239 39.0980...
## 29503 47.70056 2.2994359 POLYGON ((-94.43716 39.0353...
## 39142 47.63647 2.3635299 MULTIPOLYGON (((-94.62606 3...
## 39142.1 52.36354 2.3635412 MULTIPOLYGON (((-94.62261 3...
## 11734 52.40599 2.4059852 POLYGON ((-94.64736 39.0511...
## 11734.1 47.59401 2.4059854 POLYGON ((-94.64631 39.0477...
for (i in 1:500) {
cd %>%
filter(cd_id==dev$cd_id[i]) -> cd_i
bl %>%
filter(bl_id==dev$bl_id[i]) -> bl_i
ti <- paste0(
cd_i$CD_NAME, ", ",
bl_i$NAME20, ", ",
round(dev$pct_in[i]), "%")
cd_i %>%
ggplot(aes()) +
geom_sf(
fill="white",
color="darkgreen") +
ggtitle(ti) +
geom_sf(
data=bl_i,
aes(),
fill=NA,
color="darkred") -> map_i
plot(map_i)
}